package com.cml.rpc.client;

import com.cml.rpc.publicpojo.User;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * @author cml
 * @create 2021/7/20 12:39
 * 客服端
 */
public class RpcClient {

    public static void main(String[] args) {
        try {
            // 建立socket连接
            Socket socket = new Socket("127.0.0.1", 7788);
            System.out.println("客户端启动...");
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            // 将id传给服务端
            oos.writeInt(123);
            oos.flush();
            // 接收服务器的查询结果
            User user = (User)ois.readObject();
            System.out.println("接收到服务端返回user = " + user);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("");
        }
    }
}
